package com.csf.config;

import com.csf.quartz.PostRefreshJob;
import org.quartz.JobDataMap;
import org.quartz.JobDetail;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.JobDetailFactoryBean;
import org.springframework.scheduling.quartz.SimpleTriggerFactoryBean;

@Configuration
public class QuartzConfig {

        @Bean
        public JobDetailFactoryBean postRefreshJobFactoryBean(){
            JobDetailFactoryBean factoryBean = new JobDetailFactoryBean();
            factoryBean.setJobClass(PostRefreshJob.class);
            factoryBean.setName("postRefreshJob");
            factoryBean.setGroup("postRefreshJobGroup");
//
            factoryBean.setDurability(true);
//            是否可恢复
            factoryBean.setRequestsRecovery(true);
            return factoryBean;
        }
//    配置trigger 在什么时候触发
        @Bean
        public SimpleTriggerFactoryBean PostRefreshJobTriggerFactoryBean(JobDetail postRefreshJobFactoryBean){
                SimpleTriggerFactoryBean factoryBean = new SimpleTriggerFactoryBean();
                factoryBean.setJobDetail(postRefreshJobFactoryBean);
                factoryBean.setName("postRefreshTrigger");
                factoryBean.setGroup("postRefreshGroup");
                factoryBean.setRepeatInterval(1000*60*5);
                factoryBean.setJobDataAsMap(new JobDataMap());
                return factoryBean;
        }


}
